/* $Id:aging.h $ */
/*
   Copyright (C) 2007 by Jurjen Stellingwerff <jurjen@stwerff.xs4all.nl>
   Part of the Moros Project http://moros.sourceforge.net/

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License version 3.
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY.

   See the COPYING file for more details.
*/

#ifndef __AGING_H
#define __AGING_H

#include <string>
#include <map>
#include <list>
using namespace std;

#include "category.h"

#define loopAgingCategories(r,v) loopSingle((r)->listCategories(),v,class category,list)

class aging {
    string name;
    map<string,class category> categories;
    int maxCategories;
public:
    aging();

    // Field : name
    const string getName() const;
    void setName(const string v);

    // Field : categories
    class category& getCategories(const string v);
    list<class category>& listCategories();
    void setCategories(class category &v);
    void delCategories(const string v);
    const bool isCategories(const string v) const;

    void save(class channel &ch);
    void load(class channel &ch);
    void xml(ofstream &f, int l=0, int r=0);
};

// Repository

#define loopAgings(v) loopMap(aging_repo.listAging(),v,class aging)

class agingRepository {
    map<string,aging> agings;
public:
    class aging& getAging(const string v);
    void setAging(class aging& v);
    map<string,class aging>& listAging();
    void delAging(const string v);
    const bool isAging(const string v) const;
    multimap<string, sigc::signal<void, class aging& > > relations;
    bool load(class channel &ch);
    void save(class channel &ch);
};

extern agingRepository aging_repo;

#endif // __AGING_H
